#!/bin/bash


Pack_Tgt_Map_Lst=(
                  #"comm_msg"                                        \
                  #"dashan_msg"                                      \
                  #"comm                     libcomm.a"              \
                  #"comm_extend              libcomm_extend.a"       \
                  #"comm_ros_extend          libcomm_ros_extend.a"   \
                  #"pcpt_comm                libpcpt_comm.a"         \
                  #"data_collect_node        libdraco.a"             \
                  "camera_topic"                                     \
                  )

# 获取所有包列表，可以输出关键字进行过滤
function GetAllPackList()
{
    Pack_List=()
    for  i  in "${Pack_Tgt_Map_Lst[@]}" ; do
        Pack_Tgt_Map=($i)
        if [ ${#Pack_Tgt_Map[@]} -lt 1 ] ; then
            continue
        fi
        
        Pack=${Pack_Tgt_Map[0]}
        if [ "$1" != "" ] ; then
            result=$(echo "$Pack" | grep "$1")
            if [[ "$result" == "" ]] ; then
                continue
            fi
        fi
        
        Pack_List+=($Pack)
    done
    
    echo "${Pack_List[*]}"
}

# 获取当前存在的包列表，可以输入关键字进行过滤
function GetExistPackList()
{
    Pack_List=()
    for  i  in "${Pack_Tgt_Map_Lst[@]}" ; do
        Pack_Tgt_Map=($i)
        if [ ${#Pack_Tgt_Map[@]} -lt 1 ] ; then
            continue
        fi
        
        Pack=${Pack_Tgt_Map[0]}
        
        if [ "$1" != "" ] ; then
            result=$(echo "$Pack" | grep "$1")
            if [[ "$result" == "" ]] ; then
                continue
            fi
        fi
        
        if [ ! -d "./src/$Pack" ] ; then
            continue
        fi
        
        Pack_List+=($Pack)
    done
    
    echo "${Pack_List[*]}"
}

function GetBuildPackInfo()
{
    for  i  in "${Pack_Tgt_Map_Lst[@]}" ; do
        Pack_Tgt_Map=($i)
        if [ ${#Pack_Tgt_Map[@]} -gt 0 ] ; then
            if [ ${Pack_Tgt_Map[0]} = "$1" ] ; then
                echo "$i"
            fi
        fi
    done
    
    echo ""
}

function EchoInfo()
{
    echo "####"
    echo -e "####\033[1;31m      $1\033[0m"
    echo "####"
}

function EchoPackList()
{
    if [ "$1" = "" ] ; then
        echo "Please Input Key Info!!!!!"
        exit
    fi

    if [ "$2" = "" ] ; then
        echo "Please Input Pack List!!!!!"
        exit
    fi

    packList=($2)
    
    echo "####"
    echo -e "####\033[1;31m      $1  (Num = ${#packList[*]})\033[0m"
    
    for i in "${packList[@]}" ; do
        echo -e "####\033[1;31m          $i\033[0m"
    done
    
    echo "####"
}

